export class Page{
			constructor(options){
				this.list = options.list;
				this.url = options.url;
				this.box = options.box;
				
				this.load()
				this.addEvent()
			}
			
			load(){
				var that = this
				$.ajax({
					url:this.url,
					type:'get',
					data:{
						dataName:'column',
						rule:'time',
						start:1,
						count:100
					},
					
					success:function(res){
						// console.log(res);
						that.res = res;
						that.display()
					}
				})
				// console.log(this.box=this.list)
			}
			
			display(){
				var str = ""
				for(var i = 0;i<this.res.page_data.length;i++){
//					if(i<this.res.length){
					str +=`<li index="${this.res.page_data[i]._id}">
						<div class="sp">
							<img src="${this.res.page_data[i].detail.auth_icon}"/>
							<span class="price">¥${this.res.page_data[i].des}</span>
							<span class="preprice">¥${2*this.res.page_data[i].des}</span>
							<p class="msg">${this.res.page_data[i].title}</p>
						</div>
							<div class="join">即将开抢</div><em><em>
						</li>`
//					}
				}
				this.list.html(str)
				
			}
			
			addEvent(){
				var that = this;
				this.list.on("click",".join",function(evt){
//					that.id= $(evt.target).parent().attr("index")
					if(endTime == new Date()){
						that.id= $(this).parent().attr("index")
						that.setGoods()
					}else{
						$(this).siblings("em").html(strTime)
						setTimeout(()=>{
						$(this).siblings("em").html("")
							
						},2000)
					}
				})
				
				if(endTime == new Date()){
//				this.list.not.on("")
				this.list.on("click",".sp",function(){
					console.log($(this).parent().attr("index"))
					var a = $(this).parent().attr("index")
					var b = $(this).parent('ul').attr("dataName")
					var c = JSON.stringify({"index":a,"dataName":b})
				
					that.setgoodsdetail(c)
//					location.href="http://localhost/二升三项目/goodsdetail.html"
				})
				}
				
			}
			
			setgoodsdetail(c){
				console.log(a)
				$.cookie("goodsdetail",c)
				location.href="http://localhost/二升三项目/goodsdetail.html"
				
			}
			
			setGoods(){
//				console.log(111)
    	
//  	this.goods = $.cookie("goods")==="" ? [] : JSON.parse($.cookie("goods"))
    	if($.cookie("goods")== null){
    		this.goods=[]
    	}else{
    		this.goods= JSON.parse($.cookie("goods"))
    	}
				console.log(this.goods)
				if(this.goods.length<1){
					this.goods.push({
						id:this.id,
						num:1
					})
				}else{
					var onoff = true;
					for(var i = 0;i<this.goods.length;i++){
						if(this.goods[i].id == this.id){
							this.goods[i].num++;
							onoff = false;
							break;
						}
					}
					if(onoff){
						this.goods.push({
							id:this.id,
							num:1
						})
					}
				}
				$.cookie("goods",JSON.stringify(this.goods))
			}
			
		}

		


//		new Page({
//			list:$(".goodslist"),
//			box:$(".goodslist").not(".join"),
//			url:"data/goods.json",
//		})
//		